
//返回功能
function fanHui0() {
    history.back();
}




var y = /^1[345789]\d{9}$/;
//手机号码栏js开始

function panDuan(x) {
    if(y.test(x)){
        if(yanzhenbtn.value == "发送验证码"){
            yanzhenbtn.removeAttribute("disabled");
        }
    }else{
        yanzhenbtn.setAttribute("disabled","disabled");
    }
}
function checkephone() {
    $.get("http://test.hfjava.com/shop/userphone?phone="+ num1.value,
        {},
        function (data) {
            if(data == "false"){
                num1error.style.display = "inline";
                num1error.src = "images/error.png";
                promptbox.style.display = "block";
                promptbox.innerHTML = "该手机号已注册！";
                isPhoneRight = false;
                setTimeout(guanBi,3000);
            }else{
                num1error.style.display = "inline";
                num1error.src = "images/green.png";
                isPhoneRight = true;
            }
        }
    );
}
function panDuan2(){
    var x = parseInt(num1.value);
    num1error.style.display = "inline";
    if(y.test(x)) {
        checkephone();
    }
    else{
        num1error.src = "images/error.png";
        isPhoneRight = false;

    }
    checkAll();

}
//手机号码栏js结束
//验证码栏js开始
var timer;
var t = 60;
var z = /^\d{6}/;
//倒计时开始
yanzhenbtn.onclick = function () {
    yanzhenbtn.setAttribute("disabled","disabled");
    yanzhenbtn.value = "重新发送60";
    timer = setInterval(daojishi,1000);
};
function daojishi() {
    t--;
    if(t==0){
        clearInterval(timer);
        yanzhenbtn.value = "发送验证码";
        yanzhenbtn.removeAttribute("disabled");
        t = 60 ;
        return;
    }
    yanzhenbtn.value = "重新发送"+t;
}
//倒计时结束
//验证验证码green性
function guanBi(){
    promptbox.style.display = "none";
    promptbox.innerHTML = "";
}
num2.onblur = function () {
    var x = num2.value;
    if(!z.test(x)){
        num2error.style.display = "inline";
        num2error.src = "images/error.png";
        promptbox.style.display = "block";
        promptbox.innerHTML = "验证码格式有误！";
        isYZMRight = false;
        setTimeout(guanBi,3000);
        return;
    }
    $.ajax({
        url:"http://test.hfjava.com/shop/yzm",
        dataType:"jsonp",
        success:function (data) {
            if(data.code != x){
                promptbox.style.display = "block";
                promptbox.innerHTML = "验证码有误！";
                isYZMRight = false;
                setTimeout(guanBi,2000);
            }else{
                num2error.style.display = "inline";
                num2error.src = "images/green.png";
                isYZMRight = true;
            }
        }
    });
    checkAll();
};

//验证码栏js结束
//密码栏js
var pwdReg0 = /^.{6,16}$/;
var pwdReg1 = /\d+/;
var pwdReg2 = /[a-zA-Z]+/;
var pwdReg3 = /[=~!@#\$%^&\*\(\)_\+\{\}\]:"\|',<?.\/\\]+/;
pwd1.onblur = function () {
    var x = pwd1.value;
    var rightCount = 0;
    var lengthValid = pwdReg0.test(x);
    var numberValid = pwdReg1.test(x);
    var letterValid = pwdReg2.test(x);
    var symbolValid = pwdReg3.test(x);
    if(!x){
        promptbox.style.display = "block";
        promptbox.innerHTML = "密码不能为空！";
        isPsw1Right = false;
        setTimeout(guanBi,2000);
    }else{
        if(numberValid){
            rightCount++;
        }
        if(letterValid){
            rightCount++;
        }
        if(symbolValid){
            rightCount++;
        }
        if(!lengthValid||rightCount<2){
            num3error.style.display = "inline";
            num3error.src = "images/error.png";
            promptbox.style.display = "block";
            promptbox.innerHTML = "密码格式有误！";
            isPsw1Right = false;
            setTimeout(guanBi,2000);
            return;
        }else{
            num3error.style.display = "inline";
            num3error.src = "images/green.png";
            isPsw1Right = true;
        }
        if(pwd2.value!=""){
            checkpwd();
        }
    }
    checkAll();


};
//检查密码栏2js
pwd2.onblur =function () {
    checkpwd();
};
function checkpwd() {
    var a = pwd1.value;
    var b = pwd2.value;
    if(!b){
        promptbox.style.display = "block";
        promptbox.innerHTML = "密码不能为空！";
        isPsw2Right = false;
        setTimeout(guanBi,2000);
    }else{
        if(a === b){
            num4error.style.display = "inline";
            num4error.src = "images/green.png";
            isPsw2Right = true;
        }else{
            num4error.style.display = "inline";
            num4error.src = "images/error.png";
            promptbox.style.display = "block";
            promptbox.innerHTML = "两次密码不一致！";
            isPsw2Right = false;
            setTimeout(guanBi,2000);
        }
    }
    checkAll();

}

//获得用户是否同意注册协议
var isAgree = false;
var isPhoneRight = false;
var isYZMRight = false;
var isPsw1Right = false;
var isPsw2Right = false;
agreement.onclick = function () {
    isAgree = this.checked;
    checkAll();
};


//检测是否可以注册
function checkAll() {
    var isRight = isAgree&&isPhoneRight&&isYZMRight&&isPsw1Right&&isPsw2Right;
    if(isRight){
        loginbtn.removeAttribute("disabled");
    }else{
        loginbtn.setAttribute("disabled","disabled");
    }
}
//实现注册功能
loginbtn.onclick = function () {
    $.post(
        "http://test.hfjava.com/shop/adduser",
        $("form").serialize(),
        function (data) {
            if(data =="Saved"){
                promptbox.style.display = "block";
                promptbox.innerHTML = "注册成功！" ;
                setTimeout(deLu,2000);
            }
        }
    );
};
function deLu() {
    document.location.href ="loginpage.html";
}










//国家页js


var data = {"*":[{"中国":"86"},{"中国香港":"852"},{"中国澳门":"853"},{"中国台湾":"886"},{"新加坡":"65"},{"马来西亚":"60"},{"澳大利亚":"61"},{"加拿大":"1"},{"美国":"1"},{"新西兰":"64"},{"日本":"81"},{"韩国":"82"}],"A":[{"阿尔巴尼亚":"355"},{"阿尔及利亚":"213"},{"阿富汗":"93"},{"阿根廷":"54"},{"爱尔兰":"353"},{"埃及":"20"},{"爱沙尼亚":"372"},{"埃塞俄比亚":"251"},{"阿联酋":"971"},{"阿鲁巴":"297"},{"阿曼":"968"},{"安道尔":"376"},{"安哥拉":"244"},{"安圭拉":"1264"},{"安提瓜和巴布达":"1268"},{"澳大利亚":"61"},{"奥地利":"43"},{"阿塞拜疆":"994"}],"B":[{"巴巴多斯":"1268"},{"巴布亚新几内亚":"675"},{"巴哈马":"1242"},{"白俄罗斯":"375"},{"百慕大三角":"1441"},{"巴基斯坦":"92"},{"巴拉圭":"595"},{"巴林":"973"},{"巴拿马":"507"},{"保加利亚":"359"},{"巴西":"55"},{"贝宁":"229"},{"比利时":"32"},{"冰岛":"354"},{"博茨瓦纳":"267"},{"波多黎各":"1787"},{"波兰":"48"},{"玻利维亚":"591"},{"伯利兹":"501"},{"波斯尼亚和黑塞哥维那":"387"},{"不丹":"975"},{"布基纳法索":"226"},{"布隆迪":"257"}],"C":[{"赤道几内亚":"240"}],"D":[{"丹麦":"45"},{"德国":"49"},{"东帝汶":"670"},{"多哥":"228"},{"多米尼加共和国":"1767"}],"E":[{"厄立特里亚":"291"},{"俄罗斯":"7"}],"F":[{"法国":"33"},{"法罗群岛":"298"},{"法属圭亚那":"594"},{"斐济群岛":"679"},{"芬兰":"358"},{"佛得角":"238"}],"G":[{"冈比亚":"220"},{"格陵兰":"299"},{"格林纳达":"1473"},{"格鲁吉亚":"995"},{"哥伦比亚":"57"},{"哥斯达黎加":"506"},{"瓜德罗普":"590"},{"关岛":"1671"},{"古巴":"53"},{"圭亚那":"592"}],"H":[{"韩国":"82"},{"海地":"509"},{"哈萨克斯坦":"7"},{"黑山":"382"},{"荷兰":"31"},{"洪都拉斯":"504"}],"J":[{"加纳":"233"},{"加拿大":"1"},{"柬埔寨":"855"},{"加蓬":"241"},{"吉布提":"253"},{"捷克":"420"},{"吉尔吉斯斯坦":"996"},{"津巴布韦":"263"},{"几内亚":"224"},{"几内亚比绍":"245"}],"K":[{"开曼群岛":"1345"},{"喀麦隆":"237"},{"卡塔尔":"974"},{"克罗地亚":"385"},{"科摩罗":"269"},{"肯尼亚":"254"},{"科特迪瓦":"225"},{"科威特":"965"},{"库克群岛":"682"}],"L":[{"莱索托":"266"},{"老挝":"856"},{"拉脱维亚":"371"},{"黎巴嫩":"961"},{"利比里亚":"231"},{"利比亚":"218"},{"列支敦士登":"4175"},{"立陶宛":"370"},{"罗马尼亚":"40"},{"卢森堡":"352"},{"卢旺达":"250"}],"M":[{"马达加斯加":"261"},{"马尔代夫":"960"},{"马耳他":"356"},{"马来西亚":"60"},{"马拉维":"265"},{"马里":"223"},{"毛里求斯":"230"},{"毛里塔尼亚":"222"},{"马其顿":"389"},{"马提尼克":"596"},{"美国":"1"},{"美属萨摩亚":"684"},{"美属维尔京群岛":"1340"},{"蒙古":"976"},{"孟加拉":"880"},{"蒙特塞拉特":"1664"},{"密克罗尼西亚":"691"},{"秘鲁":"51"},{"摩尔多瓦":"373"},{"摩洛哥":"212"},{"摩纳哥":"377"},{"莫桑比克":"258"},{"墨西哥":"52"}],"N":[{"纳米比亚":"0264"},{"南非":"27"},{"厄瓜多尔":"593"},{"南苏丹":"211"},{"尼泊尔":"977"},{"尼加拉瓜":"505"},{"尼日尔":"227"},{"尼日利亚":"234"},{"挪威":"47"}],"P":[{"帕劳":"680"},{"葡萄牙":"351"}],"R":[{"日本":"81"},{"瑞典":"46"},{"瑞士":"41"}],"S":[{"萨尔瓦多":"503"},{"塞尔维亚":"381"},{"塞拉利昂":"232"},{"塞内加尔":"221"},{"塞浦路斯":"357"},{"塞舌尔":"248"},{"萨摩亚":"685"},{"沙特阿拉伯":"966"},{"圣多美和普林西比":"239"},{"圣基茨和尼维斯":"1869"},{"圣卢西亚":"1758"},{"圣马力诺":"378"},{"圣文森特和格林纳丁斯":"1784"},{"斯里兰卡":"94"},{"斯洛伐克":"421"},{"斯洛文尼亚":"386"},{"斯威士兰":"0268"},{"苏丹":"249"},{"苏里南":"597"},{"所罗门群岛":"677"},{"索马里":"252"}],"T":[{"泰国":"66"},{"汤加":"676"},{"坦桑尼亚":"255"},{"塔吉克斯坦":"992"},{"特克斯和凯科斯群岛":"1649"},{"特立尼达和多巴哥":"1868"},{"土耳其":"90"},{"突尼斯":"216"},{"图瓦卢":"688"}],"W":[{"瓦努阿图":"678"},{"危地马拉":"502"},{"委内瑞拉":"58"},{"文莱":"673"},{"乌干达":"256"},{"乌克兰":"380"},{"乌拉圭":"598"},{"乌兹别克斯坦":"998"}],"X":[{"西班牙":"34"},{"希腊":"30"},{"新加坡":"65"},{"新喀里多尼亚":"687"},{"新西兰":"64"},{"匈牙利":"36"},{"叙利亚":"963"}],"Y":[{"牙买加":"1876"},{"亚美尼亚":"374"},{"也门":"967"},{"意大利":"39"},{"伊拉克":"964"},{"伊朗":"98"},{"印度":"91"},{"印度尼西亚":"62"},{"英国":"44"},{"英属维尔京群岛":"1284"},{"以色列":"972"},{"约旦":"962"},{"越南":"84"}],"Z":[{"赞比亚":"260"},{"乍得":"235"},{"智利":"56"},{"中非":"236"},{"中国":"86"},{"中国澳门":"853"},{"中国台湾":"886"},{"中国香港":"852"}]};


//国家页js功能开始
function showCountryList(){
    countryList.style.display = "block";
    regform.style.display = "none";
}
function fanHui() {
    countryList.style.display = "none";
    xieYi.style.display = "none";
    regform.style.display = "block";
}
function fanHui0() {
    history.back();
}
//搜索功能
function searchhaha(x) {
    var lis1 = document.getElementsByName("country");
    var lis2 = document.getElementsByName("zimu");
    if(searchlan.value!== ""){

        for(var i=0;i<lis1.length;i++){
            if(lis1[i].innerHTML.indexOf(x)!== -1){
                lis1[i].style.display = "flex";
            }else{
                lis1[i].style.display = "none";
            }
        }
        for(var g=0;g<lis2.length;g++){
            lis2[g].style.display = "none";
        }
    }else{
        for(var j=0;j<lis1.length;j++){
            lis1[j].style.display = "flex";

        }
        for(var n=0;n<lis2.length;n++){
            lis2[n].style.display = "flex";
        }
    }
}
//搜索功能开始

window.onload = function (){


    for(var j=1;j<=26;j++){

        var s = String.fromCharCode(j+64);//把字符串转换成字母
        var zimuDiv = document.createElement("div");
        zimuDiv.className = "zimu";
        zimuDiv.setAttribute("name","zimu");
        zimuDiv.innerHTML = s;
        zimuDiv.id = s;
        countryList.appendChild(zimuDiv);

        var zimuDiv2 = document.createElement("div");
        zimuDiv2.className = "zimu2";
        var zimuA =  document.createElement("a");
        zimuA.innerHTML = s;
        zimuA.href = "#"+s;
        zimuDiv2.appendChild(zimuA);
        az.appendChild(zimuDiv2);

        if(data[s]){//如果该字母下有数据的话
            for(var i=0;i<data[s].length;i++){
                var p = data[s][i];
                for(var x in p){
                    // x 就是国家名称
                    // p[x] 国家编号
                    //console.log(x+" "+p[x]);
                    var countryDiv = document.createElement("div");
                    countryDiv.className = "country";
                    countryDiv.style.display = "flex";
                    countryDiv.setAttribute("name","country");

                    countryDiv.onclick = function(){
                        countryList.style.display = "none";
                        regform.style.display = "block";
                        countryCode.value = this.getElementsByTagName("div")[1].innerHTML;
                    };

                    var countryName = document.createElement("div");
                    countryName.innerHTML = x;

                    var countryNo = document.createElement("div");
                    countryNo.innerHTML = p[x];

                    countryDiv.appendChild(countryName);
                    countryDiv.appendChild(countryNo);

                    countryList.appendChild(countryDiv);
                }
            }
        }
    }
};

//国家页js结束


//用户协议页
bluee.onclick =function () {
    xieYi.style.display = "block";
    regform.style.display = "none";
};

